/**********************************************************************************************************************
 * Copyright (c) Prophesee S.A.                                                                                       *
 *                                                                                                                    *
 * Licensed under the Apache License, Version 2.0 (the "License");                                                    *
 * you may not use this file except in compliance with the License.                                                   *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0                                 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   *
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                      *
 * See the License for the specific language governing permissions and limitations under the License.                 *
 **********************************************************************************************************************/

#ifndef METAVISION_HAL_I_ERC_MODULE_H
#define METAVISION_HAL_I_ERC_MODULE_H

#include <cstdint>
#include <string>

#include "metavision/hal/facilities/i_registrable_facility.h"

namespace Metavision {

/// @brief Interface for Event Rate Controller (ERC) commands
class I_ErcModule : public I_RegistrableFacility<I_ErcModule> {
public:
    /// @brief Toggles ERC activation
    /// @param b Desired state. b = true means ERC active, and b = false means ERC inactive.
    /// @note When ERC is inactive, all the events generated by the sensor are transmitted. Potential
    /// bandwidth limitation might occur.
    /// @return true on success
    virtual bool enable(bool b) = 0;

    /// @brief Returns ERC activation state
    /// @return The ERC state
    virtual bool is_enabled() const = 0;

    /// @brief Sets the target CD event rate of the ERC
    /// @param events_per_sec Event rate expressed in events per second
    /// @note Event rate is computed by ERC block as the number of events generated by the sensor divided by the count
    /// period. To get the count period value, see @ref get_count_period.
    /// @note This method and @ref set_cd_event_count operate over the same register. It is
    /// Expected that after parameterizing ERC using event rate, result of @ref get_cd_event_count also changes.
    /// @return true on success
    virtual bool set_cd_event_rate(uint32_t events_per_sec);

    /// @brief Gets the minimum supported value for cd_event_rate setting
    virtual uint32_t get_min_supported_cd_event_rate() const;

    /// @brief Gets the maximum supported value for cd_event_rate setting
    virtual uint32_t get_max_supported_cd_event_rate() const;

    /// @brief Gets the CD event rate set point of the ERC
    /// @return The event rate expressed in events per second
    /// @note See @ref set_cd_event_rate to define the event rate target.
    virtual uint32_t get_cd_event_rate() const;

    /// @brief Gets the count period
    /// @return The count period duration expressed in microseconds
    virtual uint32_t get_count_period() const = 0;

    /// @brief Sets the maximum number of events that ERC block should let pass over the count period
    /// @param event_count The desired maximum number of event per reference period
    /// @note If you wish to parameterize the ERC with a set point expressed with an event rate
    /// use @ref set_cd_event_rate instead. The 2 methods operate on the same register and conversions
    /// are managed automatically.
    /// @return true on success
    virtual bool set_cd_event_count(uint32_t event_count) = 0;

    /// @brief Gets the minimum supported value for cd_event_count setting
    virtual uint32_t get_min_supported_cd_event_count() const = 0;

    /// @brief Gets the maximum supported value for cd_event_count setting
    virtual uint32_t get_max_supported_cd_event_count() const = 0;

    /// @brief Gets the maximum number of events that ERC will transmit over the count period
    /// @return The maximum event count
    /// @note See @ref set_cd_event_count to define the event count parameter.
    virtual uint32_t get_cd_event_count() const = 0;

    /// @cond DEV
    virtual void erc_from_file(const std::string &) = 0;
    /// @endcond
};

} // namespace Metavision

#endif // METAVISION_HAL_I_ERC_MODULE_H
